package com.hmdp.controller;

import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller 用户关注
 */
@Api(tags = "用户关注")
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Resource
    private IFollowService followService;

    @ApiOperation("关注/取消关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "目标用户id", required = true, example = "1", dataType = "long"),
            @ApiImplicitParam(name = "isFollow", value = "是否关注", required = true, example = "false", dataType = "bool")})
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followUserId,
                         @PathVariable("isFollow") Boolean isFollow) {
        return followService.follow(followUserId, isFollow);
    }

    @ApiOperation("查询登录用户是否关注目标用户")
    @ApiImplicitParam(name = "id", value = "目标用户id", required = true, example = "1", dataType = "long")
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId) {
        return followService.isFollow(followUserId);
    }

    @ApiOperation("查询登录用户和目标用户的共同关注")
    @ApiImplicitParam(name = "id", value = "目标用户id", required = true, example = "1", dataType = "long")
    @GetMapping("/common/{id}")
    public Result followCommons(@PathVariable("id") Long id){
        return followService.followCommons(id);
    }

}
